/*
* (C) Copyright 2013 Philip Kirchhoff 
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*-------------------------------------------------------------------------------
* This file is part of the DataLogger library by Philip Kirchhoff
* https://code.google.com/p/pk-data-logger/
* SVN: http://pk-data-logger.googlecode.com/svn/trunk
*-------------------------------------------------------------------------------
* Module    : DlTimestamp.h   
* Author    : Kirchhoff, Philip
* Date      : 01.04.2013
*-------------------------------------------------------------------------------
* Header file for DlTimestamp class
*   
*-------------------------------------------------------------------------------
* Change History:
* 01.04.2013  Kirchhoff 	Created
--------------------------------------------------------------------------------
*/
*/
#ifndef DL_TIMESTAMP_H
#define DL_TIMESTAMP_H

#include <string>
#include <ctime>

/***************************************************************************//**
* @brief Timestamp class for DataLogger datasets
 ******************************************************************************/
class DlTimestamp
{
public:

    /**************************************************************************//**
    * @brief Creates an unatilialised timestamp object
    ******************************************************************************/
	DlTimestamp();

    /**************************************************************************//**
    * @brief Creates timestamp object from another one
    ******************************************************************************/
	DlTimestamp(const DlTimestamp& other);

    /**************************************************************************//**
    * @brief Set year
    ******************************************************************************/
	void setYear(int year){timeStruct.tm_year = year-1900;}
    /**************************************************************************//**
    * @brief Set month 1...12
    ******************************************************************************/
	void setMonth(int month){timeStruct.tm_mon = month-1;}
    /**************************************************************************//**
    * @brief Set month day 1...31
    ******************************************************************************/
	void setDay(int day){timeStruct.tm_mday = day;}
    /**************************************************************************//**
    * @brief Set hour 0...23
    ******************************************************************************/
	void setHour(int hour){timeStruct.tm_hour = hour;}
    /**************************************************************************//**
    * @brief Set minute 0...59
    ******************************************************************************/
	void setMinute(int minute){timeStruct.tm_min = minute;}
    /**************************************************************************//**
    * @brief Set second 0...59
    ******************************************************************************/
	void setSecond(int second){timeStruct.tm_sec = second;}
    /**************************************************************************//**
    * @brief Set microseconds 0...999999
    ******************************************************************************/
	void setUSecond(int uSecond){mUSecond = uSecond;}

    /**************************************************************************//**
    * @brief Get yaer
    ******************************************************************************/
    int year(){return timeStruct.tm_year + 1900;}
    /**************************************************************************//**
    * @brief Get month
    ******************************************************************************/
    int month(){return timeStruct.tm_mon + 1;}
    /**************************************************************************//**
    * @brief Get day
    ******************************************************************************/
    int day(){return timeStruct.tm_mday;}
    /**************************************************************************//**
    * @brief Get hour
    ******************************************************************************/
    int hour(){return timeStruct.tm_hour;}
    /**************************************************************************//**
    * @brief Get minute
    ******************************************************************************/
    int minute(){return timeStruct.tm_min;}
    /**************************************************************************//**
    * @brief Get second
    ******************************************************************************/
    int scond(){return timeStruct.tm_sec;}
    /**************************************************************************//**
    * @brief Get microsecond
    ******************************************************************************/
    int uSecond(){return mUSecond;}

    /**************************************************************************//**
    * @brief Converts the timestamp to a DataLogger .cfg-file string
    ******************************************************************************/
	std::string toDlString();

    /**************************************************************************//**
    * @brief Creates a new timestamp that differs a specified number of
    *			microseconds
    ******************************************************************************/
    DlTimestamp diffUs(long long microSeconds);


private:
    /**************************************************************************//**
    * @brief Standard ctime tm struct. Stores all time information except the
    *		number of microseconds
    ******************************************************************************/
	tm timeStruct;

    /**************************************************************************//**
    * @brief Number of microseconds (0...999,999)
    ******************************************************************************/
	int mUSecond;
};

#endif
